/**
 * Copyright 2022 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MINDSPORE_CCSRC_FL_WORKER_NODE_H_
#define MINDSPORE_CCSRC_FL_WORKER_NODE_H_

#include <cstdlib>
#include <iostream>
#include <memory>
#include <string>
#include <utility>
#include <algorithm>

#include "common/core/cluster_config.h"
#include "communicator/tcp_client.h"
#include "communicator/tcp_server.h"
#include "common/core/abstract_node.h"
#include "common/utils/visible.h"
#include "common/fl_context.h"

namespace mindspore {
namespace fl {
class MS_EXPORT WorkerNode : public AbstractNode {
 public:
  WorkerNode() = default;
  ~WorkerNode() override = default;

  bool Start(const uint32_t &timeout = FLContext::instance()->cluster_config().cluster_available_timeout) override;
  bool Stop() override;

  bool Send(const NodeRole &node_role, const void *message, size_t len, int command, VectorPtr *output = nullptr,
            const uint32_t &timeout = kCommTimeoutInSeconds);
  std::string fl_id() const { return fl_id_; }

 private:
  void Initialize();
  std::string fl_id_;
};
}  // namespace fl
}  // namespace mindspore

#endif  // MINDSPORE_CCSRC_FL_WORKER_NODE_H_
